﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FySystem.Extension
{
    public static class StringExtension
    {
        /// <summary>
        /// 如果为空，返回目标字符串
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        /// <returns></returns>
        public static string NVL(this string source, string dest = "")
        {
            return string.IsNullOrWhiteSpace(source) ? dest : source;
        }

        /// <summary>
        /// 如果传入为null，返回""，如果传入中前后包含空格，则将其去除
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string Fmt(this string source)
        {
            if (source == null)
                return "";
            else if (source.StartsWith(' ') || source.EndsWith(' '))
                return source.Trim();
            else
                return source;
        }

        /// <summary>
        /// 获取GUID字符串，全部大写，并且没有-
        /// </summary>
        /// <returns></returns>
        public static string GetGUID()
        {
            return Guid.NewGuid().ToString().ToUpper().Replace("-", "");
        }
    }
}
